<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文件上传 - 组件演示</title>
    <link rel="stylesheet" href="../css/style.css">
    <link rel="stylesheet" href="../components/upload/upload.css">
</head>
<body>
    <div class="container">
        <header class="header">
            <h1>🚀 openHarmony_Cordova_NutpiDesign</h1>
            <p class="subtitle">组件演示 - 文件上传</p>
        </header>

        <nav class="demo-nav">
            <a href="../index.html" class="nav-back">← 返回首页</a>
        </nav>

        <main class="main-content">
            <section class="demo-section">
                <h2>📤 文件上传演示</h2>
                
                <div class="demo-container">
                    <div class="demo-item">
                        <h3>自动上传</h3>
                        <div id="autoUpload"></div>
                    </div>

                    <div class="demo-item">
                        <h3>手动上传</h3>
                        <div id="manualUpload"></div>
                        <button class="btn btn-primary" onclick="manualUploadInstance.uploadAll()" style="margin-top: 12px; width: 100%;">上传所有文件</button>
                    </div>

                    <div class="demo-item">
                        <h3>图片上传</h3>
                        <div id="imageUpload"></div>
                    </div>

                    <div class="demo-item">
                        <h3>限制大小</h3>
                        <div id="limitedUpload"></div>
                    </div>
                </div>
            </section>

            <section class="demo-section">
                <h2>使用代码</h2>
                <pre><code>// 1. 引入文件
&lt;link rel="stylesheet" href="components/upload/upload.css"&gt;
&lt;script src="components/upload/upload.js"&lt;/script&gt;

// 2. 创建容器
&lt;div id="uploadContainer"&lt;/div&gt;

// 3. 初始化上传组件
const upload = new Upload({
    container: '#uploadContainer',
    uploadUrl: '/api/upload',
    onSuccess: (result) => {
        console.log('上传成功:', result);
    },
    onError: (error) => {
        console.log('上传失败:', error);
    }
});

// 4. 获取文件列表
const files = upload.getFiles();

// 5. 手动上传
upload.uploadAll();</code></pre>
            </section>
        </main>

        <footer class="footer">
            <p>&copy; 2025 OpenHarmony 三方库适配中心 | MIT License</p>
        </footer>
    </div>

    <script src="../components/upload/upload.js"></script>
    <script>
        // 自动上传
        const autoUpload = new Upload({
            container: '#autoUpload',
            uploadUrl: '/api/upload',
            onSuccess: (result) => {
                console.log('自动上传成功:', result);
            },
            onError: (error) => {
                console.log('自动上传失败:', error);
            }
        });

        // 手动上传
        let manualUploadInstance = new Upload({
            container: '#manualUpload',
            autoUpload: false,
            uploadUrl: '/api/upload',
            onSuccess: (result) => {
                console.log('手动上传成功:', result);
            },
            onError: (error) => {
                console.log('手动上传失败:', error);
            }
        });

        // 图片上传
        const imageUpload = new Upload({
            container: '#imageUpload',
            accept: 'image/*',
            uploadUrl: '/api/upload',
            onSuccess: (result) => {
                console.log('图片上传成功:', result);
            }
        });

        // 限制大小
        const limitedUpload = new Upload({
            container: '#limitedUpload',
            maxSize: 2 * 1024 * 1024, // 2MB
            uploadUrl: '/api/upload',
            onSuccess: (result) => {
                console.log('限制大小上传成功:', result);
            }
        });
    </script>

    <style>
        .demo-container {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
            gap: 20px;
            margin-bottom: 20px;
        }

        .demo-item {
            background: var(--bg-light);
            padding: 16px;
            border-radius: 8px;
            overflow: visible;
            position: relative;
        }

        .demo-item h3 {
            margin-top: 0;
            margin-bottom: 16px;
            font-size: 16px;
            color: var(--text-primary);
        }

        .demo-item > div {
            margin-bottom: 12px;
            overflow: visible;
        }

        .btn {
            padding: 10px 16px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 14px;
            transition: var(--transition);
        }

        .btn-primary {
            background: var(--primary-color);
            color: white;
        }

        .btn-primary:hover {
            opacity: 0.9;
        }

        @media (max-width: 768px) {
            .demo-container {
                grid-template-columns: 1fr;
            }
        }
    </style>
</body>
</html>
